﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=1">
    <meta name="format-detection" content="telephone=no">
    <meta charset="UTF-8">
    <title>简易todo</title>
    <link rel="stylesheet" href="../css/bootstrap.css"/>
    <script src="../js/jquery-2.2.0.min.js"></script>
    <script src="../js/bootstrap.min.js"></script>
</head>
<body>
    <h1>简易todo</h1><br/>

    <div id="app">
        {{name}}
        <!--
            键盘修饰符keyup.enter就是按回车就行，.13直接写键盘码也行。
            keyup.ctrl.enter表示需要用户按ctrl+enter同时按
        -->
        <input type="text" v-model="val" @keyup.ctrl.enter="add">
        <ul>
            <li v-for="(obj,i) in arr">{{obj}}<button @click="del(i)">删除</button></li>
        </ul>
    </div>
<script src="../js/vue-2.5.16.js"></script>
<script src="../node_modules/axios/dist/axios.js"></script>
<script src="../node_modules/lodash/lodash.js"></script>

<script>
    var app = new Vue({
        el:'#app',
        data:{
            name:'模版数据',
            val:'',
            arr:[]
        },
        methods:{
            add(){
                this.arr.unshift(this.val);
                this.val = '';
            },
            del(i){
                /*this.arr = this.arr.filter((item,index)=>{
                    if(index!==i){//相等的返回false
                        return true;
                    }
                })*/
                //简写    时刻记住箭头函数里不写{}   则会return    filter只要返回true就是留下该项这样就起到了删除的功能了。
                this.arr = this.arr.filter((item,index)=>index!==i);
            }
        }
    });
</script>

</body>
</html>